package com.zhaoyue.study.concurrency.thread.daemon;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: zhaoyue
 * Date: 2016/8/30
 * Time: 17:32
 * 写入任务
 */
public class WriteTask implements Runnable {


    private LinkedBlockingDeque<Event> queue;
    public WriteTask(LinkedBlockingDeque<Event> queue){
        this.queue = queue;
    }


    public void run() {

        for(int i = 1;i<100;i++){
            Event event = new Event();
            event.setDate(new Date());
            event.setEvent("the thread " + Thread.currentThread().getId() + " has an event");
            queue.addFirst(event);
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch (InterruptedException e){
                e.printStackTrace();
            }

        }
    }


}
